<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix"><span>优惠券</span></div>
    <div>
      <el-collapse v-model="activeNames">
        <el-collapse-item title="内容" name="1">
          <draggable
            element="div"
            style="padding: 10px"
            v-model="data.list"
            :animation="200"
          >
            <div class="container" v-for="(item, i) in data.list" :key="i">
              <div class="bg-color">
                <i class="iconfont icon-move move-icon"></i>
                <div class="body">
                  <p class="name">{{ item.name }}</p>
                  <p class="demon"></p>
                </div>
              </div>
              <i class="el-icon-error cancal" @click="dellist(i)"></i>
            </div>
          </draggable>
          <el-button @click="addCon" style="width: 100%">添加</el-button>
        </el-collapse-item>
        <el-collapse-item title="组件样式" name="2">
          <el-form size="medium" label-width="100px">
            <el-form-item label="组件背景颜色"
              ><ColorPicker :color="data" :name="'bg_div_color'"></ColorPicker
            ></el-form-item>

            <el-form-item label="文字颜色"
              ><ColorPicker :color="data" :name="'textcolor'"></ColorPicker
            ></el-form-item>
            <el-form-item label="背景颜色"
              ><ColorPicker :color="data" :name="'bgcolor'"></ColorPicker
            ></el-form-item>

            <el-form-item label="排列方式">
              <el-radio-group size="medium" v-model="data.show_type">
                <el-radio label="scroll">单行</el-radio>
                <el-radio label="block">多行</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-form>
        </el-collapse-item>
      </el-collapse>
    </div>
    <el-dialog
      title="选择优惠券"
      :visible.sync="showSelectCon"
      width="50%"
      append-to-body
      ><SelectConpon
        :key="rk"
        :data="selectPro"
        @outData="closePro"
      ></SelectConpon
    ></el-dialog>
  </el-card>
</template>

<script>
import SelectConpon from "@/components/SelectConpon/index";
import draggable from "vuedraggable";
import ColorPicker from "@/components/ColorPicker/index";

export default {
  props: {
    data: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      showSelectCon: false,
      selectPro: [],
      rk: 0,
      activeNames: ["1", "2"],
    };
  },
  components: {
    draggable,
    SelectConpon,
    ColorPicker,
  },
  methods: {
    dellist(i) {
      this.data.list.splice(i, 1);
    },
    selectlink(list) {
      this.$parent.showlinkselcet(list);
    },
    //添加商品
    addCon() {
      this.selectPro = this.data.list;
      this.rk++;
      this.showSelectCon = true;
    },
    //关闭选择优惠券框
    closePro(data) {
	if(data){
		this.data.list=data
	}
		
      this.showSelectCon = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.container {
  display: flex;
  align-items: center;
  border: 1px solid #e9edef;
  background: #f4f6f8;
  padding: 10px;
  margin-bottom: 20px;
  position: relative;

  > i {
    font-size: 24px;
  }

  &:hover {
    .cancal {
      display: block;
    }
  }

  .cancal {
    font-size: 20px;
    position: absolute;
    right: -10px;
    top: -10px;
    cursor: pointer;
    display: none;
  }
}
.bg-color {
  box-sizing: border-box;
  border-radius: 2px;
  // padding: 10px;
  background: #f4f6f8;
  display: flex;
  align-items: center;
  p {
    margin: 0;
  }
  .coupon-img {
  }
  .body {
    margin-left: 15px;
  }
}
</style>
